<?php

namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;

class InstpersonController extends \App\Http\Controllers\AdminController {
    /**
     * 装维人员管理
     */
    public function index() {
        $instpersons = \App\Models\InstPerson::paginate();
        return view("admin.instper.index", ['instpersons'=>$instpersons]);
    }
    
    /**
     * 添加装维人员
     */
    public function add(Request $request) {
        if ($request->ajax()) {
            return \Illuminate\Support\Facades\Response::json(\App\Models\InstPerson::addInstPer($request));
        }
        $plots = \App\Models\Plot::where("status", 1)->orderBy('area', 'asc')->get();
        $assign = compact('plots');
        return view("admin.instper.add", $assign);
    }
    /**
     * 重新分配管理小区
     */
    public function modPlot(Request $request, $iperid) {
        if ($request->ajax()) {
            return \Illuminate\Support\Facades\Response::json(\App\Models\Iperplot::addIperPlot($request, $iperid));
        }
        $iplots = \App\Models\Iperplot::where('iperid', $iperid)->get();
        $iplotsarr = array();
        foreach ($iplots as $val) {
            $iplotsarr[] = $val->plotid;
        }
        $instperson = \App\Models\InstPerson::find($iperid);
        $plots = \App\Models\Plot::where("status", 1)->orderBy('area', 'asc')->get();
        $assign = compact('plots', 'instperson', 'iplotsarr');
        return view('admin.instper.modplot', $assign);
    }
    
}
